<template>
  <div>
    <v-edit
      :init="comm"
      :infos="info"
      @reset="reset"
      @save="save"
      @close="close"
      :rules="rules"
    >
      <template #formItem>
        <div class="one-col intro-y">
          <wde-input label="姓名" prop="tchName" v-model="info.tchName" />
        </div>
        <div class="two-col intro-y">
          <wde-number
            label="金额(万元)"
            :isFloat="true"
            :floatNumber="6"
            v-model="info.price"
          />
        </div>
        <div class="two-col intro-y">
          <wde-price label="金额(万元)" v-model="info.price" />
        </div>
        <div class="two-col intro-y">
          <wde-muti-select
            label="等级"
            v-model="info.levels"
            :options="options"
          />
        </div>
        <div class="two-col intro-y">
          <wde-select label="项目类型" v-model="info.type" :options="options" />
          <wde-muti-select
            label="等级"
            v-model="info.levels"
            :options="options"
          />
        </div>
        <div class="two-col intro-y">
          <wde-date label="计划开始时间" dateType="date" v-model="info.date" />
        </div>
        <div class="two-col intro-y">
          <wde-switch label="是否激活" v-model="info.isActive" />
        </div>
      </template>
    </v-edit>
  </div>
</template>

<script setup>
import { ref, toRefs, watch, getCurrentInstance } from "vue";
import { useEditLogic } from "@/views/base/useEditLogic";
import * as $api from "@/api/api.js";
const { proxy } = getCurrentInstance();
const emit = defineEmits(["close"]);

const props = defineProps({
  args: {
    type: Object,
    default: () => null,
  },
  init: {
    type: Object,
    default: () => null,
  },
});
// 使用 toRefs 解构 props
const { init } = toRefs(props);
const info = ref({
  tchName: "",
  price: 500000,
  date: new Date(),
  type: "",
  levels: [],
  isActive: true,
});
// const info = ref({
//   tchKey: "",
//   tchNum: "",
//   tchName: "",
//   sex: true,
//   tel: "",
//   email: "",
//   title: "",
//   birthday: "",
//   nation: "",
//   idType: "",
//   idCode: "",
//   stopFlag: true,
//   remark: "",
// });
const options = ref([
  {
    value: "Option1",
    label: "Option1",
  },
  {
    value: "Option2",
    label: "Option2",
  },
  {
    value: "Option3",
    label: "Option3",
  },
  {
    value: "Option4",
    label: "Option4",
  },
  {
    value: "Option5",
    label: "Option5",
  },
]);
const rules = ref({
  tchName: [
    { required: true, message: "请输入姓名", trigger: "blur" },
    { min: 2, max: 5, message: "长度在 2 到 5 个字符", trigger: "blur" },
  ],
});
const buildAdd = () => {
  console.log(info.value);
  // 构建新增逻辑
};

const buildUpdate = () => {
  console.log(info.value);
  // return $api.BATeacherUpdate(info.value);
};
const resetAdd = () => {
  proxy.$propsEmpty(info.value);
  // proxy.$propsCopy(info.value, props.init);
};
const resetUpdate = () => {
  proxy.$propsCopy(info.value, props.init);
};
const clearInfo = () => {
  proxy.$propsEmpty(info.value);
};

const close = () => {
  emit("close");
};
const { loading, comm, isView, reset, save, VEdit } = useEditLogic(
  init,
  info,
  resetAdd,
  resetUpdate,
  clearInfo,
  buildAdd,
  buildUpdate,
  close
);
watch(
  () => comm,
  (newVal) => {
    console.log(newVal);
  }
);
watch(
  () => props.init,
  (newVal) => {
    console.log(newVal);
  }
);
</script>

<style>
</style>